-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Diagnostics] Return rvalue reference from temporary argument #127400
Conversation
@llvm/pr-subscribers-llvm-ir Author: Jonas Hahnfeld (hahnjo) ChangesThis fixes compilation issues with GCC and C++23:
Closes #105778 Full diff: https://github.com/llvm/llvm-project/pull/127400.diff 3 Files Affected:
diff --git a/llvm/include/llvm/Analysis/OptimizationRemarkEmitter.h b/llvm/include/llvm/Analysis/OptimizationRemarkEmitter.h
index 7b14e55782adb..2640bb9194010 100644
--- a/llvm/include/llvm/Analysis/OptimizationRemarkEmitter.h
+++ b/llvm/include/llvm/Analysis/OptimizationRemarkEmitter.h
@@ -69,6 +69,11 @@ class OptimizationRemarkEmitter {
/// Output the remark via the diagnostic handler and to the
/// optimization record file.
void emit(DiagnosticInfoOptimizationBase &OptDiag);
+ /// Also allow r-value for OptDiag to allow emitting a temporarily-constructed
+ /// diagnostic.
+ void emit(DiagnosticInfoOptimizationBase &&OptDiag) {
+ emit(static_cast<DiagnosticInfoOptimizationBase &>(OptDiag));
+ }
/// Take a lambda that returns a remark which will be emitted. Second
/// argument is only used to restrict this to functions.
diff --git a/llvm/include/llvm/IR/DiagnosticInfo.h b/llvm/include/llvm/IR/DiagnosticInfo.h
index 694785317af04..1e26cfdd17b5f 100644
--- a/llvm/include/llvm/IR/DiagnosticInfo.h
+++ b/llvm/include/llvm/IR/DiagnosticInfo.h
@@ -30,6 +30,7 @@
#include <iterator>
#include <optional>
#include <string>
+#include <utility>
namespace llvm {
@@ -625,14 +626,14 @@ operator<<(RemarkT &R,
/// Also allow r-value for the remark to allow insertion into a
/// temporarily-constructed remark.
template <class RemarkT>
-RemarkT &
+RemarkT &&
operator<<(RemarkT &&R,
std::enable_if_t<
std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value,
StringRef>
S) {
R.insert(S);
- return R;
+ return std::move(R);
}
template <class RemarkT>
@@ -647,14 +648,14 @@ operator<<(RemarkT &R,
}
template <class RemarkT>
-RemarkT &
+RemarkT &&
operator<<(RemarkT &&R,
std::enable_if_t<
std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value,
DiagnosticInfoOptimizationBase::Argument>
A) {
R.insert(A);
- return R;
+ return std::move(R);
}
template <class RemarkT>
@@ -669,14 +670,14 @@ operator<<(RemarkT &R,
}
template <class RemarkT>
-RemarkT &
+RemarkT &&
operator<<(RemarkT &&R,
std::enable_if_t<
std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value,
DiagnosticInfoOptimizationBase::setIsVerbose>
V) {
R.insert(V);
- return R;
+ return std::move(R);
}
template <class RemarkT>
@@ -690,6 +691,17 @@ operator<<(RemarkT &R,
return R;
}
+template <class RemarkT>
+RemarkT &&
+operator<<(RemarkT &&R,
+ std::enable_if_t<
+ std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value,
+ DiagnosticInfoOptimizationBase::setExtraArgs>
+ EA) {
+ R.insert(EA);
+ return std::move(R);
+}
+
/// Common features for diagnostics dealing with optimization remarks
/// that are used by IR passes.
class DiagnosticInfoIROptimization : public DiagnosticInfoOptimizationBase {
diff --git a/llvm/lib/Analysis/InlineAdvisor.cpp b/llvm/lib/Analysis/InlineAdvisor.cpp
index 12553dd446a61..2041610cd5ee9 100644
--- a/llvm/lib/Analysis/InlineAdvisor.cpp
+++ b/llvm/lib/Analysis/InlineAdvisor.cpp
@@ -338,7 +338,7 @@ static raw_ostream &operator<<(raw_ostream &R, const ore::NV &Arg) {
}
template <class RemarkT>
-RemarkT &operator<<(RemarkT &&R, const InlineCost &IC) {
+RemarkT &operator<<(RemarkT &R, const InlineCost &IC) {
using namespace ore;
if (IC.isAlways()) {
R << "(cost=always)";
@@ -352,6 +352,12 @@ RemarkT &operator<<(RemarkT &&R, const InlineCost &IC) {
R << ": " << ore::NV("Reason", Reason);
return R;
}
+
+template <class RemarkT>
+RemarkT &&operator<<(RemarkT &&R, const InlineCost &IC) {
+ static_cast<RemarkT &>(R) << IC;
+ return std::move(R);
+}
} // namespace llvm
std::string llvm::inlineCostStr(const InlineCost &IC) {
|
@llvm/pr-subscribers-llvm-analysis Author: Jonas Hahnfeld (hahnjo) ChangesThis fixes compilation issues with GCC and C++23:
Closes #105778 Full diff: https://github.com/llvm/llvm-project/pull/127400.diff 3 Files Affected:
diff --git a/llvm/include/llvm/Analysis/OptimizationRemarkEmitter.h b/llvm/include/llvm/Analysis/OptimizationRemarkEmitter.h
index 7b14e55782adb..2640bb9194010 100644
--- a/llvm/include/llvm/Analysis/OptimizationRemarkEmitter.h
+++ b/llvm/include/llvm/Analysis/OptimizationRemarkEmitter.h
@@ -69,6 +69,11 @@ class OptimizationRemarkEmitter {
/// Output the remark via the diagnostic handler and to the
/// optimization record file.
void emit(DiagnosticInfoOptimizationBase &OptDiag);
+ /// Also allow r-value for OptDiag to allow emitting a temporarily-constructed
+ /// diagnostic.
+ void emit(DiagnosticInfoOptimizationBase &&OptDiag) {
+ emit(static_cast<DiagnosticInfoOptimizationBase &>(OptDiag));
+ }
/// Take a lambda that returns a remark which will be emitted. Second
/// argument is only used to restrict this to functions.
diff --git a/llvm/include/llvm/IR/DiagnosticInfo.h b/llvm/include/llvm/IR/DiagnosticInfo.h
index 694785317af04..1e26cfdd17b5f 100644
--- a/llvm/include/llvm/IR/DiagnosticInfo.h
+++ b/llvm/include/llvm/IR/DiagnosticInfo.h
@@ -30,6 +30,7 @@
#include <iterator>
#include <optional>
#include <string>
+#include <utility>
namespace llvm {
@@ -625,14 +626,14 @@ operator<<(RemarkT &R,
/// Also allow r-value for the remark to allow insertion into a
/// temporarily-constructed remark.
template <class RemarkT>
-RemarkT &
+RemarkT &&
operator<<(RemarkT &&R,
std::enable_if_t<
std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value,
StringRef>
S) {
R.insert(S);
- return R;
+ return std::move(R);
}
template <class RemarkT>
@@ -647,14 +648,14 @@ operator<<(RemarkT &R,
}
template <class RemarkT>
-RemarkT &
+RemarkT &&
operator<<(RemarkT &&R,
std::enable_if_t<
std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value,
DiagnosticInfoOptimizationBase::Argument>
A) {
R.insert(A);
- return R;
+ return std::move(R);
}
template <class RemarkT>
@@ -669,14 +670,14 @@ operator<<(RemarkT &R,
}
template <class RemarkT>
-RemarkT &
+RemarkT &&
operator<<(RemarkT &&R,
std::enable_if_t<
std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value,
DiagnosticInfoOptimizationBase::setIsVerbose>
V) {
R.insert(V);
- return R;
+ return std::move(R);
}
template <class RemarkT>
@@ -690,6 +691,17 @@ operator<<(RemarkT &R,
return R;
}
+template <class RemarkT>
+RemarkT &&
+operator<<(RemarkT &&R,
+ std::enable_if_t<
+ std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value,
+ DiagnosticInfoOptimizationBase::setExtraArgs>
+ EA) {
+ R.insert(EA);
+ return std::move(R);
+}
+
/// Common features for diagnostics dealing with optimization remarks
/// that are used by IR passes.
class DiagnosticInfoIROptimization : public DiagnosticInfoOptimizationBase {
diff --git a/llvm/lib/Analysis/InlineAdvisor.cpp b/llvm/lib/Analysis/InlineAdvisor.cpp
index 12553dd446a61..2041610cd5ee9 100644
--- a/llvm/lib/Analysis/InlineAdvisor.cpp
+++ b/llvm/lib/Analysis/InlineAdvisor.cpp
@@ -338,7 +338,7 @@ static raw_ostream &operator<<(raw_ostream &R, const ore::NV &Arg) {
}
template <class RemarkT>
-RemarkT &operator<<(RemarkT &&R, const InlineCost &IC) {
+RemarkT &operator<<(RemarkT &R, const InlineCost &IC) {
using namespace ore;
if (IC.isAlways()) {
R << "(cost=always)";
@@ -352,6 +352,12 @@ RemarkT &operator<<(RemarkT &&R, const InlineCost &IC) {
R << ": " << ore::NV("Reason", Reason);
return R;
}
+
+template <class RemarkT>
+RemarkT &&operator<<(RemarkT &&R, const InlineCost &IC) {
+ static_cast<RemarkT &>(R) << IC;
+ return std::move(R);
+}
} // namespace llvm
std::string llvm::inlineCostStr(const InlineCost &IC) {
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
This fixes compilation issues with GCC and C++23: ``` error: cannot bind non-const lvalue reference of type 'llvm::OptimizationRemarkMissed&' to an rvalue of type 'llvm::OptimizationRemarkMissed' ``` Closes llvm#105778
e0e37c9
to
3b0573b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like OK changes.
I wouldn't mind a unit test for something low level/broadly used like this, but wouldn't insist on it.
I generally agree, but unfortunately there is none for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM % nit
@arsenm thanks for merging. However, for future changes I would prefer to do this myself, both to decide on the author email address (work or private; this merge got it right because I contributed privately outside of work hours) and to make sure I'm available to respond to any issues reported by the bots... |
This fixes compilation issues with GCC and C++23:
Closes #105778